import { Button, Switch, Tooltip } from "antd";
import { formatDate } from "@/utils";
import { UpdatedUserInfoService } from "@/service";
import type { FormRule } from "antd";

export type FuncType = (item?: any, callback?: () => void) => void;
// fn4 更新用户信息
export default function (
  fn1: FuncType,
  fn2: FuncType,
  fn3: FuncType,
  fn4: (...args: any[]) => void,
  fn5: FuncType,
  department: any[],
  userStore: any
) {
  const columns = [
    {
      title: "#",
      dataIndex: "index",
      align: "center",
      width: "60px",
      fixed: true,
      key: "index",
      render: (text: string, record: any, index: number) => (
        <span>{index + 1}</span>
      ),
    } as const,
    {
      title: "用户名",
      dataIndex: "nick_name",
      key: "nick_name",
      align: "center",
      width: "145px",
      fixed: true,
    } as const,
    {
      title: "真实姓名",
      dataIndex: "user_name",
      align: "center",
      key: "user_name",
      width: "145px",
      fixed: true,
    } as const,
    {
      title: "Avatar",
      dataIndex: "avatar",
      key: "index",
      width: "100px",
      render: (text: string, record: any, index: number) => (
        <div className="cursor-pointer w-12 h-12 rounded-full mx-2 overflow-hidden">
          <img src={record.avatar} alt="avatar" />
        </div>
      ),
    } as const,
    {
      title: "手机号码",
      dataIndex: "phone",
      key: "phone",
      align: "center",
    } as const,
    {
      title: "邮箱",
      dataIndex: "email",
      key: "email",
      align: "center",
    } as const,
    {
      title: "性别",
      dataIndex: "sex",
      key: "sex",
      width: "65px",
      align: "center",
    } as const,
    {
      title: "部门",
      dataIndex: "department",
      key: "department",
      width: "105px",
      align: "center",
    } as const,
    {
      title: "状态",
      dataIndex: "status",
      key: "status",
      align: "center",
      width: "100px",
      render: (text: any, record: any, index: number) => {
        return (
          <Switch
            checkedChildren="开启"
            unCheckedChildren="关闭"
            disabled={record.id == 1}
            checked={record.status == "1"}
            onChange={() => fn4(record, "status")}
          />
        );
      },
    } as const,
    {
      title: "Mail",
      dataIndex: "mail_is_allowed",
      key: "mail_is_allowed",
      align: "center",
      width: "100px",
      render: (text: any, record: any, index: number) => {
        return (
          <Switch
            checkedChildren="开启"
            unCheckedChildren="关闭"
            checked={record.mail_is_allowed}
            onChange={() => fn4(record, "")}
          />
        );
      },
    } as const,
    {
      title: "库存盘点",
      dataIndex: "update_banlace",
      key: "update_banlace",
      align: "center",
      width: "100px",
      render: (text: any, record: any, index: number) => {
        return (
          <Switch
            checkedChildren="开启"
            unCheckedChildren="关闭"
            checked={record.update_balance}
            onChange={() => {
              console.log("record update_balance", record);
              fn4(record, "update_balance");
            }}
          />
        );
      },
    } as const,
    {
      title: "操作",
      dataIndex: "operate",
      align: "center",
      key: "index",
      width: "220px",
      fixed: "right",
      render: (text: any, record: any, index: number) => (
        <>
          <Button
            className="mb-1"
            onClick={() => fn1(record, fn3)}
            type="primary"
            disabled={!userStore.user.department.includes("SSS")}
            size="small"
          >
            编辑
          </Button>
          <Button
            type="primary"
            size="small"
            style={{ margin: "0 5px" }}
            danger
            disabled={!userStore.user.department.includes("SSS")}
            onClick={() => fn2(record)}
          >
            删除
          </Button>
          <Button
            disabled={!userStore.user.department.includes("SSS")}
            onClick={() => fn5(record)}
            type="primary"
            size="small"
          >
            菜单控制
          </Button>
        </>
      ),
    } as const,
  ];
  const config = [
    {
      label: "真实姓名",
      name: "username",
      span: 8,
      placeholder: "请填写名字",
      type: "input",
    },
    {
      label: "手机号码",
      name: "phone",
      span: 8,
      placeholder: "请填写手机号码",
      type: "input",
    },
    {
      label: "电子邮箱",
      name: "email",
      span: 8,
      placeholder: "请填写电子邮箱",
      type: "input",
    },
    {
      label: "部门",
      name: "department",
      span: 8,
      placeholder: "请填写部门",
      type: "select",
      options: department,
    },
    {
      label: "性别",
      name: "sex",
      span: 8,
      placeholder: "请填写性别",
      type: "select",
      options: [
        { value: "男", label: "男" },
        { value: "女", label: "女" },
      ],
    },
    {
      label: "创建时间",
      name: "created_at",
      placeholders: ["请选择开始时间", "请选择结束时间"],
      span: 8,
      type: "date",
      rules: [],
    },
  ];
  return {
    columns,
    config,
  };
}
